//
//  LRLoadingCommentCell.swift
//  LRWeibo
//
//  Created by 雷路荣 on 15/12/26.
//  Copyright © 2015年 leilurong. All rights reserved.
//
/**
*  正在加载微博评论数据cell，应用显示正在加载微博评论和菊花转
*/
import UIKit

class LRLoadingCommentCell: LRCommentCell {

    
    override func prepareForReuse() {
        super.prepareForReuse()
        refreshingView.startAnimating()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
    }
    //重写父类方法
    override func prepareUI() {
        //super.prepareUI()//不要调用父类
        //添加控件
        contentView.addSubview(refreshingView)
        contentView.addSubview(tipLabel)
        //取消autoresizing
        refreshingView.translatesAutoresizingMaskIntoConstraints = false
        tipLabel.translatesAutoresizingMaskIntoConstraints = false
        //设置约束
        //设置菊花
        contentView.addConstraint(NSLayoutConstraint(item: refreshingView, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: contentView, attribute: NSLayoutAttribute.CenterX, multiplier: 1, constant: -40))
        contentView.addConstraint(NSLayoutConstraint(item: refreshingView, attribute: NSLayoutAttribute.CenterY, relatedBy: NSLayoutRelation.Equal, toItem: contentView, attribute: NSLayoutAttribute.CenterY, multiplier: 1, constant: 0))
        //设置提示文字
        contentView.addConstraint(NSLayoutConstraint(item: tipLabel, attribute: NSLayoutAttribute.Left, relatedBy: NSLayoutRelation.Equal, toItem: refreshingView, attribute: NSLayoutAttribute.Right, multiplier: 1, constant: 8))
        contentView.addConstraint(NSLayoutConstraint(item: tipLabel, attribute: NSLayoutAttribute.CenterY, relatedBy: NSLayoutRelation.Equal, toItem: contentView, attribute: NSLayoutAttribute.CenterY, multiplier: 1, constant: 0))
        //设置cell的contentView高度
        contentView.addConstraint(NSLayoutConstraint(item: contentView, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: 44))
    }
 
    //正在刷新指示器--菊花
    private lazy var refreshingView: UIActivityIndicatorView = {
        let view = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.Gray)
        view.color = UIColor.magentaColor()
        view.startAnimating()
        view.hidesWhenStopped = true
        return view
    }()
    //提示文字
    private lazy var tipLabel: UILabel = {
        let label = UILabel(fontSize: 18, textColor: UIColor.darkGrayColor())
        label.text = "正在加载评论..."
        label.sizeToFit()
        return label
    }()

}
